package com.wxx.controller.bg;

import com.wxx.service.bg.DicRoleAclService;
import com.wxx.util.JsonData;
import com.wxx.vo.AclZtreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bg/dicRoleAcl/")
public class DicRoleAclController {

    @Autowired
    private DicRoleAclService dicRoleAclService;


    /**
     * 跳转到设置权限列表页面
     * @return
     */
    @RequestMapping(value = "toSetAcl",method = RequestMethod.GET)
    public String toSetAcl(Model model, String roleId){
        model.addAttribute("roleId",roleId);
        return "dicRole/setAcl";
    }

    /**
     * 查询权限列表（组装选中的权限和所有权限的数据）
     * @return
     */
    @RequestMapping(value = "findSetAcl",method = RequestMethod.POST)
    @ResponseBody
    public Object findSetAcl(String roleId){
        List<AclZtreeVo> aclZtreeVoList = dicRoleAclService.findAssemblyAcl(roleId);
        return JsonData.success(aclZtreeVoList);
    }

    /**
     * 保存角色权限关系
     * @return
     */
    @RequestMapping(value = "addRoleAcl",method = RequestMethod.POST)
    @ResponseBody
    public Object addRoleAcl(HttpServletRequest request,String nodeString, String roleId){
        Map map =dicRoleAclService.addRoleAcl(request,nodeString,roleId);
        return map;
    }



}
